import json

import requests


class KWMusic:
    url = "https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash=%s&dfid=1IMNoH1UgWpe0tFYfP38DeTY&appid=1014&mid=e40696aee6ecdded2a01c4994d29ef15&platid=4&album_id=%s"

    payload = {}
    headers = {
        'authority': 'wwwapi.kugou.com',
        'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
        'sec-ch-ua-mobile': '?0',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
        'accept': '*/*',
        'sec-fetch-site': 'same-site',
        'sec-fetch-mode': 'no-cors',
        'sec-fetch-dest': 'script',
        'referer': 'https://www.kugou.com/',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cookie': 'kg_mid=e40696aee6ecdded2a01c4994d29ef15; kg_dfid=1IMNoH1UgWpe0tFYfP38DeTY; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1642480368,1644038790; KuGoo=KugooID=647825972&KugooPwd=633E03139BD4C7E332568FE5E8A057D3&NickName=%u0061%u006e%u006a%u0069%u0065%u0034%u0030%u0036%u0030%u0031%u0031%u0033&Pic=http://imge.kugou.com/kugouicon/165/20100101/20100101192931478054.jpg&RegState=1&RegFrom=&t=ed4b13effdcd0c033f99e6a5aff201c8cc9451bcc9ebef55ba5f9f37e553e3ac&t_ts=1644038849&t_key=&a_id=1014&ct=1644038849&UserName=%u0061%u006e%u006a%u0069%u0065%u0034%u0030%u0036%u0030%u0031%u0031%u0033; KugooID=647825972; t=ed4b13effdcd0c033f99e6a5aff201c8cc9451bcc9ebef55ba5f9f37e553e3ac; a_id=1014; UserName=%u0061%u006e%u006a%u0069%u0065%u0034%u0030%u0036%u0030%u0031%u0031%u0033; mid=e40696aee6ecdded2a01c4994d29ef15; dfid=1IMNoH1UgWpe0tFYfP38DeTY; kg_mid_temp=e40696aee6ecdded2a01c4994d29ef15; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1644039794'
    }

    def getPath(self, id, hash):
        okurl = self.url % (hash, id)
        response = requests.request("GET", okurl, headers=self.headers, data=self.payload)
        print(response.text)
        print(response.text)
        loads = json.loads(response.text)
        return {
            "name": None,
            "wma": loads["data"]["play_url"],
            "m4a": None,
            "name": loads["data"]['audio_name']
        }
